styleproperty: Move value printing to real properties
authorBenjamin Otte <otte@redhat.com>
Sun, 1 Jan 2012 17:28:27 +0000 (18:28 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 9 Jan 2012 17:37:53 +0000 (18:37 +0100)
We can't print shorthands, so don't try.
In particular, I want to get away from shorthands being representable
using GValue, and this function kinda requires that.

gtk/gtkcssprovider.c
gtk/gtkcssstyleproperty.c
gtk/gtkcssstylepropertyprivate.h
gtk/gtkstyleproperty.c
gtk/gtkstylepropertyprivate.h

index d25fba6a10cc2667d22d977c9d4b661a9fd312e2..f24ef0d098f2848cda05403f1f330535e5a699de 100644 (file)
@@ -3282,13 +3282,13 @@ gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
 
       for (walk = keys; walk; walk = walk->next)
         {
-          GtkStyleProperty *prop = walk->data;
+          GtkCssStyleProperty *prop = walk->data;
           const PropertyValue *value = g_hash_table_lookup (ruleset->style, prop);
 
           g_string_append (str, "  ");
-          g_string_append (str, _gtk_style_property_get_name (prop));
+          g_string_append (str, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop)));
           g_string_append (str, ": ");
-          _gtk_style_property_print_value (prop, &value->value, str);
+          _gtk_css_style_property_print_value (prop, &value->value, str);
           g_string_append (str, ";\n");
         }
 
index 66ce7ff020a5c971dc3fd95fd0e7f64f28db312a..da902278146eda57ca1a6c4a39ce86b5ca0006a7 100644 (file)
 
 #include "gtkcssstylepropertyprivate.h"
 
+#include "gtkcssstylefuncsprivate.h"
+#include "gtkcsstypesprivate.h"
 #include "gtkintl.h"
+#include "gtkprivatetypebuiltins.h"
 
 enum {
   PROP_0,
@@ -227,3 +230,40 @@ _gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
   return &property->initial_value;
 }
 
+/**
+ * _gtk_css_style_property_print_value:
+ * @property: the property
+ * @value: the value to print
+ * @string: the string to print to
+ *
+ * Prints @value to the given @string in CSS format. The @value must be a
+ * valid specified value as parsed using the parse functions or as assigned
+ * via _gtk_style_property_assign().
+ **/
+void
+_gtk_css_style_property_print_value (GtkCssStyleProperty    *property,
+                                     const GValue           *value,
+                                     GString                *string)
+{
+  g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
+  g_return_if_fail (value != NULL);
+  g_return_if_fail (string != NULL);
+
+  if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
+    {
+      GEnumClass *enum_class;
+      GEnumValue *enum_value;
+
+      enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_VALUE);
+      enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
+
+      g_string_append (string, enum_value->value_nick);
+
+      g_type_class_unref (enum_class);
+    }
+  else if (GTK_STYLE_PROPERTY (property)->print_func)
+    (* GTK_STYLE_PROPERTY (property)->print_func) (value, string);
+  else
+    _gtk_css_style_print_value (value, string);
+}
+
index 32ab48dfdda314f23345864653045c9a63d3e2be..aba791c6666d3d209db72722b192487ab81775b5 100644 (file)
@@ -61,6 +61,10 @@ guint                   _gtk_css_style_property_get_id          (GtkCssStyleProp
 const GValue *          _gtk_css_style_property_get_initial_value
                                                                 (GtkCssStyleProperty    *property);
 
+void                    _gtk_css_style_property_print_value     (GtkCssStyleProperty    *property,
+                                                                 const GValue           *value,
+                                                                 GString                *string);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_STYLE_PROPERTY_PRIVATE_H__ */
index 204e1e8d0d9f79aa21d2595e786d26cb07cf8320..25556a7fbccf8c8316e75012f64203959617136c 100644 (file)
@@ -201,22 +201,6 @@ string_append_string (GString    *str,
 
 /*** IMPLEMENTATIONS ***/
 
-static void
-enum_print (int         value,
-           GType       type,
-           GString    *string)
-{
-  GEnumClass *enum_class;
-  GEnumValue *enum_value;
-
-  enum_class = g_type_class_ref (type);
-  enum_value = g_enum_get_value (enum_class, value);
-
-  g_string_append (string, enum_value->value_nick);
-
-  g_type_class_unref (enum_class);
-}
-
 static gboolean
 font_family_parse (GtkCssParser *parser,
                    GFile        *base,
@@ -453,19 +437,6 @@ _gtk_style_property_parse_value (GtkStyleProperty *property,
   return _gtk_css_style_parse_value (value, parser, base);
 }
 
-void
-_gtk_style_property_print_value (GtkStyleProperty *property,
-                                 const GValue     *value,
-                                 GString          *string)
-{
-  if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
-    enum_print (g_value_get_enum (value), GTK_TYPE_CSS_SPECIAL_VALUE, string);
-  else if (property && property->print_func)
-    (* property->print_func) (value, string);
-  else
-    _gtk_css_style_print_value (value, string);
-}
-
 static void
 _gtk_style_property_default_value (GtkStyleProperty   *property,
                                    GtkStyleProperties *properties,
index e8d6e583d4b9cac626b6384235299f74babd302f..92c3fea1800d74ab2276f5957e718813d5e0fd0b 100644 (file)
@@ -95,9 +95,6 @@ gboolean                 _gtk_style_property_parse_value   (GtkStyleProperty *
                                                             GValue                 *value,
                                                             GtkCssParser           *parser,
                                                             GFile                  *base);
-void                     _gtk_style_property_print_value   (GtkStyleProperty *      property,
-                                                            const GValue           *value,
-                                                            GString                *string);
 
 GType                    _gtk_style_property_get_value_type(GtkStyleProperty *      property);
 void                     _gtk_style_property_query         (GtkStyleProperty *      property,